package com.example.service.impl;

import com.example.mapper.CoachCommentMapper;
import com.example.pojo.CoachComment;
import com.example.service.CoachCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class CoachCommentServiceImp implements CoachCommentService {
    @Autowired
    private CoachCommentMapper coachCommentMapper;
    @Override
    public CoachComment selectCoachCommentById(int id) {
        return coachCommentMapper.selectCoachCommentById(id);
    }

    @Override
    public List<CoachComment> selectCoachCommentByCid(int cid) {
        return coachCommentMapper.selectCoachCommentByCid(cid);
    }

    @Override
    public List<CoachComment> selectAll() {
        return coachCommentMapper.selectAll();
    }

    @Override
    public int insertCoachComment(int uid,int cid,String comment,String time) {
        CoachComment coachComment = new CoachComment();
        coachComment.setCid(cid);
        coachComment.setUid(uid);
        coachComment.setComment(comment);
        LocalDateTime localDate=LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        coachComment.setTime(localDate);
        return coachCommentMapper.insertCoachComment(coachComment);
    }

    @Override
    public int deleteCoachCommentById(int id) {
        return coachCommentMapper.deleteCoachCommentById(id);
    }

    @Override
    public int updateCoachComment(int uid,int cid,String comment,String time) {
        CoachComment coachComment = new CoachComment();
        coachComment.setCid(cid);
        coachComment.setUid(uid);
        coachComment.setComment(comment);
        LocalDateTime localDate=LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        coachComment.setTime(localDate);
        return coachCommentMapper.updateCoachComment(coachComment);
    }
}
